package com.tamir.template.util;

import java.util.Date;

/**
 * @author : tanggh
 * @description : 本地序列生成类
 * @date : 2016/10/28
 */
public class SequenceLocal
{
    private static Date date = new Date();
    private static StringBuilder buf = new StringBuilder();
    private static int seq = 0;
    private static final int ROTATION = 99999;

    /**
     * 获取唯一序列id
     * @return
     */
    public static synchronized String getSeq(){
        if (seq > ROTATION) seq = 0;
        buf.delete(0, buf.length());
        date.setTime(System.currentTimeMillis());
        String str = String.format("%1$tY%1$tm%1$td%1$tk%1$tM%1$tS%2$05d", date, seq++);
        return str;
    }

    public static void main(String[] args) throws Exception
    {
        for (int i=0; i<10; i++)
        {
            System.out.println(SequenceLocal.getSeq());
        }
    }
}
